//
//  MineViewControl.m
//  豆瓣zlw
//
//  Created by lanou3g on 16/1/11.
//  Copyright © 2016年 zlw. All rights reserved.
//

#import "MineViewControl.h"
#import "MyActiveCollectionViewController.h"
#import "MyMoviewCollectionViewController.h"
#import "LoginViewController.h"
#import "Moive_Data.h"
#import "DataBase.h"

@interface MineViewControl ()<UITableViewDelegate,UITableViewDataSource>
{
    NSMutableArray *arrAllData;
   
    
}



@end

@implementation MineViewControl

-(void)viewWillAppear:(BOOL)animated
{
    NSUserDefaults * defaults=[NSUserDefaults standardUserDefaults];
    
    BOOL isLongin = [defaults boolForKey:@"User"];
    self.navigationItem.rightBarButtonItem.title=isLongin?@"注销":@"登录";
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.HUD hide:YES];
    self.MineTbleView.delegate=self;
    self.MineTbleView.dataSource=self;
    arrAllData=[NSMutableArray arrayWithObjects:@"我的活动",@"我的电影",@"清除缓存", nil];
    

    // Do any additional setup after loading the view.
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{
    static NSString *id1 = @"cell_id";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:id1];
    if (cell==nil)
    {
        cell=[[UITableViewCell alloc] initWithStyle:(UITableViewCellStyleSubtitle) reuseIdentifier:id1];
    }
    cell.textLabel.text=arrAllData[indexPath.row];
    return cell;
}
#pragma mark----------点击事件-----------
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row==0)
    {
        MyActiveCollectionViewController *ActiveVC=[[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"Min_Mine_Active"];
        [self.navigationController pushViewController:ActiveVC animated:YES];

        
    }else if (indexPath.row==1)
    {
        MyMoviewCollectionViewController *MovieVC=[[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"Min_Mine_Movie"];
        
        [self.navigationController pushViewController:MovieVC animated:YES];
   
        
    }else if (indexPath.row==2)
    {
        
            [[DataBase shareData] deleteActive];
            [[DataBase shareData] closeData];
        
        
        [[Moive_Data shareMoiveData] deleteMoiveData];
        [[Moive_Data shareMoiveData] closeMoiveData];
            //显示UIAlertView提示用户
            UIAlertView *alertView=[self showAlertViewWithTitle:@"提示" message:@"删除活动成功" cancelButtonTitle:nil otherButtonTitle:nil];
            //1秒之后消失
        [alertView dismissWithClickedButtonIndex:0.5 animated:YES];

       
    }
}
- (IBAction)Mine__LogAction:(id)sender {
    NSUserDefaults *user=[NSUserDefaults standardUserDefaults];
    
    if ([self.navigationItem.rightBarButtonItem.title isEqualToString:@"登录"])
    {
        [user setBool:NO forKey:@"User"];
        [user synchronize];
        LoginViewController *VC=[[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"MinLog"];
        [self.navigationController pushViewController:VC animated:YES];
    }else
    {
        [user setBool:NO forKey:@"User"];
        [user synchronize];
        self.navigationItem.rightBarButtonItem.title=@"登录";
    }
    
    
    
    
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
